/*
 * @Author: huangrongji
 * @Date: 2021-11-26 23:10:36
 * @LastEditors: huangrongji
 * @LastEditTime: 2021-11-28 23:01:10
 * @Description: file content
 */
const path = require('path'),
  TransformPages = require('uni-read-pages'),
  { webpack } = new TransformPages();
  
module.exports = {
  transpileDependencies: ['uview-ui'],
  configureWebpack: {
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        img: path.resolve(__dirname, 'src/static/images'),
      },
    },
    plugins: [
      new webpack.DefinePlugin({
        ROUTES: webpack.DefinePlugin.runtimeValue(() => {
          const tfPages = new TransformPages({
            includes: ['path', 'name', 'meta', 'aliasPath']
          });
          return JSON.stringify(tfPages.routes)
        }, true)
      })
    ]
  },
  devServer: {
    port: 9090,
    open: true,
    // 跨域代理
    proxy: {
      '/api': {
        target: 'https://css.dglightyear.com',
        changeOrigin: true,
        pathRewrite: { '^/api': '' },
      },
      '/cdn': {
        target: 'https://repair-1259727252.file.myqcloud.com',
        changeOrigin: true,
        pathRewrite: { '^/cdn': '' },
      },
    },
  },
  chainWebpack: config => {
    // 修复HMR
    config.resolve.symlinks(true);
    config.plugins.delete('prefetch');
    config.output.filename('[name].[hash].js').end();
  },
}